import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

 class IntCmp  implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }

}
public class test {
    public static void main2(String[] args) {
        //创建一个空的优先级队列,默认是小根堆排序,可以在括号里指定初始大小
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();//默认是小根堆
        priorityQueue.offer(44);
        priorityQueue.offer(23);
        priorityQueue.offer(4);
        System.out.println(priorityQueue);//[4, 44, 23]

        //用比较器创建一个优先级队列,是以大根堆排序
        PriorityQueue<Integer> priorityQueuebig = new PriorityQueue<>(new IntCmp());//利用比较器创建出来的是大根堆
        priorityQueuebig.offer(44);
        priorityQueuebig.offer(23);
        priorityQueuebig.offer(4);
        System.out.println(priorityQueuebig);//[44, 23, 4]

        //用一个集合来创建优先级队列
        List<Integer> list = Arrays.asList(3, 1, 4, 1, 5);
        PriorityQueue<Integer> priorityQueue1 = new PriorityQueue<>(list);
        System.out.println(priorityQueue1);//[1, 1, 4, 3, 5]
    }
    public static void main1(String[] args) {
        int arr[] = {27,15,19,18,28,34,65,49,25,37};
        TestHeap testHeap = new TestHeap();
        testHeap.initElem(arr);//初始化
        testHeap.createHeap();
    }

}
